import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../components/Login.vue"
import Home from "../components/Home.vue";
import Role from "../components/Role.vue";
import Power from '../components/Power.vue'
import Welcome from "../components/Welcome.vue"
import IdType from "../components/IdType"
import AccountType from '../components/AccountType'
import Licensetype from '../components/Licensetype'
import Member from '../components/Member.vue'
import Assets from '../components/Assets.vue'
import User from '../components/User.vue'
import Register from '../components/Register.vue'
import Cert from '../components/Cert.vue'
import Mycf from '../components/Mycf.vue'
import StartHome from "../components/StartHome.vue"
import S_S_1 from "../components/Start-Step-1.vue"
import S_S_2 from "../components/Start-Step-2.vue"
import S_S_3 from "../components/Start-Step-3.vue"
import S_S_4 from "../components/Start-Step-4.vue"
import A_P from "../components/Auth-Project.vue"
import P_T from "../components/Project-Type.vue"
import Start from '../components/Start.vue'
import Index from '../components/Index.vue'
import Advert from '../components/Advert.vue'
import AdvertSH from '../components/AdvertSH.vue'
import AdvertGL from '../components/AdvertGl.vue'
import Test from '../components/Test.vue'
import ZC from '../components/ZC.vue'
import Projects from '../components/Projects.vue'
import SupportDetail from '../components/SupportDetail.vue'
import Pay_step_0 from "../components/pay_step_0.vue"
import Pay_step_1 from "../components/pay_step_1.vue"
import Pay_step_2 from "../components/pay_step_2.vue"
import Pay_step_3 from "../components/pay_step_3.vue"

Vue.use(VueRouter)

const routes = [
	{path: "/" , redirect:"/index"},
	{path:'/index',component:Index},
	{path:'/projects',component:Projects},
	{path:'/login',component:Login},
	{path: "/register" , component:Register},
	{path: "/home" , component: Home, redirect:'/welcome', children:[
		{path: "/welcome" , component: Welcome},
		{path: "/role" , component: Role},
		{path:'/idtype',component:IdType},
		{path:'/licensetype',component:Licensetype},
		{path:'/categorytype',component:AccountType},
		{path:'/user',component:User},
		{path:'/cert',component:Cert},
		{path:'/power',component:Power},
		{path: "/a_p", component: A_P},
		{path: "/p_t", component: P_T},
		{path: "/advertsh", component: AdvertSH},
		{path: "/advergl", component: AdvertGL}
	]},
	//新的
	{path:"/start",component:Start},
	{path: "/startHome" , component: StartHome, redirect:"/s_s_1", children:[
	    {path: "/s_s_1" , component: S_S_1},
	    {path: "/s_s_2/:iid" , component: S_S_2},
	    {path: "/s_s_3/:iid" , component: S_S_3},
	    {path: "/s_s_4" , component: S_S_4}
	]},
	{path:"/member",component:Member,redirect:"/assets",children:[
		{path: "/assets" , component: Assets,redirect:"/mycf",children:[
			{path: "/mycf", component:Mycf},
			{path: "/zc",component:ZC},
			{path: "/tomzc",component:Mycf},
			{path:'/advert', component:Advert}
		]},
		
	]},
	{path:'/test', component:Test},
	{path:'/supportDetail/:iid',component:SupportDetail},
	{path:'/pay_step_0', component: Pay_step_0,redirect:"/pay_step_1",children:[
	    {path:'/pay_step_1', component: Pay_step_1},
	    {path:'/pay_step_2', component: Pay_step_2},
	    {path:'/pay_step_3', component: Pay_step_3},
	  ]}
]

const router = new VueRouter({
  routes
})

// 定义路由守卫，判断如果非/login之外的请求，没有登录，则默认跳转登录页面取登录
router.beforeEach((to,from,next)=>{
	// 判断如果是/login，则释放
	if(to.path == '/index' || to.path == '/login' || to.path == '/register'){
		return next();
	}
	//判断如果sessionStroy中没有数据，则为未登录，跳转到取登录的页面
	var token =  window.sessionStorage.getItem("token")
	if(!token){ //没有数据
		return next('/index')  // 如果token值没有，则跳转到 login页面
	}
	next();  // 进入你的请求中
})

export default router
